package middle;

import java.util.Arrays;

/**
 * 189. 旋转数组
 */
public class Rotate {
    public static void main(String[] args) {
        int[] nums = new int[]{-4,-1,0,3,10};
        int[] arrays = rotate(nums,3);
        System.out.println(Arrays.toString(arrays));
    }

    public static int[] rotate(int[] nums,int k) {
        int n = nums.length;
        if (k>n){
            k=k%n;
        }
        int[] arrys = new int[n];
        for(int i=0;i<n;i++){
            if (i+k>=n){
                arrys[i] = nums[ i+k-n];
            }else {
                arrys[i] = nums[i+k];
            }
        }
        return arrys;
    }
}
